package com.ebt.m;

import android.util.Log;

import com.ebt.m.data.middle.EBTFileWriter;
import com.ebt.m.utils.ConfigData;
import com.ebt.m.utils.TimeUtils;

import java.io.File;
import java.util.Date;

/**
 * 应用程序的Log管理器
 *
 * @author
 * @version 1.0
 * @created 2013-11-24
 */
public class AppLog {
    private static final boolean SHOW_ACTIVITY_STATE = true;

    public static final void debug(String msg) {
        if (ConfigData.DEBUG) {
            Log.i("----debug----", msg);
        }
    }

    public static final void debug(String msg, Throwable tr) {
        if (ConfigData.DEBUG) {
            Log.i("debug", msg, tr);
        }
    }

    public static final void state(Class cls, String state) {
        if (SHOW_ACTIVITY_STATE) {
            Log.d("state", cls + state);
        }
    }

    /**
     * 打印长内容到文件中
     *
     * @param content 文件名规范：文件名不能有空格等特殊字符
     */
    public static final void writeContentToSdcardFile(String fileName, String content) {
        if (ConfigData.DEBUG) {
            String path = ConfigData.DATA_PATH + File.separator + "appLog";
            File ff = new File(path);
            if (!ff.exists()) {
                ff.mkdirs();
            }
            debug("content is " + content);
            EBTFileWriter.writeFileUTF8(path + File.separator + TimeUtils.dateTime2String(new Date(), TimeUtils.YYYYMMDDHHMMSS) + fileName,
                    content);// 将文件写入sd卡用于测试查看
        }
    }
}
